package com.galgram.project.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.galgram.project.entity.Collect;
import com.galgram.project.entity.Course;
import com.galgram.project.entity.News;
import com.galgram.project.mapper.FxCourseDetailMapper;
import com.galgram.project.mapper.FxCourseMapper;
import com.galgram.project.mapper.FxNewsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.galgram.project.mapper.FxCollectMapper;
import com.galgram.project.domain.FxCollect;
import com.galgram.project.service.IFxCollectService;

/**
 * 用户收藏Service业务层处理
 *
 * @author galgram
 * @date 2024-11-20
 */
@Service
public class FxCollectServiceImpl extends ServiceImpl<FxCollectMapper, FxCollect> implements IFxCollectService {
    @Autowired
    private FxCollectMapper collectMapper;
    @Autowired
    private FxCourseMapper courseMapper;
    @Autowired
    private FxNewsMapper newsMapper;

    @Override
    public List<FxCollect> selectFxCollectList(FxCollect fxCollect) {
        return baseMapper.selectFxCollectList(fxCollect);
    }

    @Override
    public int deleteCollect(FxCollect fxCollect) {
        return baseMapper.deleteCollect(fxCollect);
    }

    @Override
    public List<Collect> getUserCollectList(Collect collect) {
        List<Collect> userCollectList = collectMapper.getUserCollectList(collect);
        for (int i = 0; i < userCollectList.size(); i++) {
            userCollectList.get(i).setCourse(courseMapper.getCourseById(userCollectList.get(i).getCourseId()));
            userCollectList.get(i).setNews(newsMapper.getNewsById(userCollectList.get(i).getNewsId()));
        }
        return userCollectList;
    }

}
